package com.sunagy.demand.backend.handler;

import com.sunagy.demand.backend.VO.ResultVO;
import com.sunagy.demand.backend.exception.*;
import com.sunagy.demand.backend.utils.ResultVOUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * desc：#TODO fill me ！
 * author：三餘無夢生
 * date：2018/4/25
 * time：下午2:12
 */
@ControllerAdvice
public class MazExceptionHandler {

    @ExceptionHandler(value = {TokenNoneException.class})
    public ResponseEntity<Object> handlerAuthorizeException(){
        ResultVO resultVO = ResultVOUtil.fail("没有传入Token");
        return new ResponseEntity<Object>(resultVO, HttpStatus.OK);
    }
    @ExceptionHandler(value = {AdminUserNotFoundException.class})
    public ResponseEntity<Object> handlerUserNotFoundException(){
        ResultVO resultVO = ResultVOUtil.fail("用户不存在");
        return new ResponseEntity<Object>(resultVO, HttpStatus.OK);
    }
    @ExceptionHandler(value = {AdminUserIncorrectPasswordException.class})
    public ResponseEntity<Object> handlerIncorrectPasswordException(){
        ResultVO resultVO = ResultVOUtil.fail("密码错误");
        return new ResponseEntity<Object>(resultVO, HttpStatus.OK);
    }
    @ExceptionHandler(value = {TokenNotFoundException.class})
    public ResponseEntity<Object> handlerTokenNotFoundException(){
        ResultVO resultVO = ResultVOUtil.fail("Token不存在");
        return new ResponseEntity<Object>(resultVO, HttpStatus.UNAUTHORIZED);
    }
    @ExceptionHandler(value = {TokenExpiredException.class})
    public ResponseEntity<Object> handlerTokenExpiredException(){
        ResultVO resultVO = ResultVOUtil.fail("Token已过期");
        return new ResponseEntity<Object>(resultVO, HttpStatus.UNAUTHORIZED);
    }
    @ExceptionHandler(value = {UsernameExistException.class})
    public ResponseEntity<Object> handlerUsernameExistException(){
        ResultVO resultVO = ResultVOUtil.fail("用户名已存在");
        return new ResponseEntity<Object>(resultVO, HttpStatus.OK);
    }
    @ExceptionHandler(value = {SmsSendTooFastException.class})
    public ResponseEntity<Object> handlerSmsSendTooFastException(){
        ResultVO resultVO = ResultVOUtil.fail("短信验证码发送过于频繁");
        return new ResponseEntity<Object>(resultVO, HttpStatus.OK);
    }
    @ExceptionHandler(value = {IncorrectSmsCodeException.class})
    public ResponseEntity<Object> handlerIncorrectSmsCodeException(){
        ResultVO resultVO = ResultVOUtil.fail("短信验证码错误");
        return new ResponseEntity<Object>(resultVO, HttpStatus.OK);
    }

    @ExceptionHandler(value = {OpenidNotFoundException.class})
    public ResponseEntity<Object> handlerOpenidNotFoundException(){
        ResultVO resultVO = ResultVOUtil.fail("openid不存在");
        return new ResponseEntity<Object>(resultVO, HttpStatus.OK);
    }

    @ExceptionHandler(value = {OpenidHasBindException.class})
    public ResponseEntity<Object> handlerOpenidHasBindException(){
        ResultVO resultVO = ResultVOUtil.fail("openid不能重复绑定");
        return new ResponseEntity<Object>(resultVO, HttpStatus.OK);
    }
    @ExceptionHandler(value = {PhoneHasBindException.class})
    public ResponseEntity<Object> handlerPhoneHasBindException(){
        ResultVO resultVO = ResultVOUtil.fail("手机号不能重复绑定");
        return new ResponseEntity<Object>(resultVO, HttpStatus.OK);
    }
    @ExceptionHandler(value = {VerifyCodeIsNullException.class})
    public ResponseEntity<Object> handlerVerifyCodeIsNullException(){
        ResultVO resultVO = ResultVOUtil.fail("验证码不能为空");
        return new ResponseEntity<Object>(resultVO, HttpStatus.OK);
    }




}
